package com.jt.tenant.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;


import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.PolylineOptions;
import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetFreeWayDetail;


public class FreewayOrbitActivity extends JTV4Activity implements View.OnClickListener {

    private TextureMapView mapView;

    private AMap aMap;

    private GetFreeWayDetail.DetailItem detailItem = new GetFreeWayDetail.DetailItem();

    private String travel_id;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_freeway_orbit);

        mapView = (TextureMapView) findViewById(R.id.freeway_detail_guiji);

        mapView.onCreate(savedInstanceState);

        aMap = mapView.getMap();

        detailItem = (GetFreeWayDetail.DetailItem) getIntent().getSerializableExtra("item");

        initView();

    }

    private void initView() {

        aMap.clear();

        PolylineOptions polylineOptions = new PolylineOptions().width(5).color(Color.parseColor("#1873f8"));

        for (int i = 0; i < detailItem.gpsList.size(); i++) {

            GetFreeWayDetail.Gps gps = detailItem.gpsList.get(i);

            LatLng latLng = new LatLng(gps.LATITUDE, gps.LONGITUDE);

            if (i == 0) {

                aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13));

                aMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromView(JTApplication.ScaleScreenHelper.loadView((ViewGroup) getLayoutInflater().inflate(R.layout.location_start, null)))).position(latLng).snippet(detailItem.start_point).draggable(true));

            } else if (i == detailItem.gpsList.size() - 1) {

                aMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromView(JTApplication.ScaleScreenHelper.loadView((ViewGroup) getLayoutInflater().inflate(R.layout.location_end, null)))).position(latLng).snippet(detailItem.end_point).draggable(true));

            }

            polylineOptions.add(latLng);

        }

        aMap.addPolyline(polylineOptions);


    }


    @Override
    public void onClick(View view) {



    }

    @Override
    protected void onResume() {

        super.onResume();

        mapView.onResume();

    }

    @Override
    protected void onPause() {

        super.onPause();

        mapView.onPause();

    }

    @Override
    protected void onDestroy() {

        super.onDestroy();

        mapView.onDestroy();

    }

}
